﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using lite;
using System.Data.SqlClient;
using Csla.Data;
using Csla;
using OpenExpressApp;
using System.Collections;
using Csla.Core;
using OpenExpressApp.ORM;
using OpenExpressApp.MetaAttribute;
using OpenExpressApp.DB.Utils;
using OpenExpressApp.Types;
using OpenExpressApp.Command;

namespace OpenExpressApp.Module.Library
{
    [Serializable]
    public partial class OperationList : GBusinessListBase<OperationList, Operation>
    {
        internal static Operation Get(Guid guid)
        {
            var cmd = ApplicationModel.Commands.First<OpenExpressApp.Command.CommandBase>(x => x.Id.ToUpper() == guid.ToString().ToUpper());
            return new Operation(cmd);
        }

        protected OperationList()
        {
            /* require use of factory methods */
            AllowNew = true;
            /* 不允许修改时，AutoUI绑定列表控件时会使得控件只读  */
            //AllowEdit = false;            
        }
    }

    [Serializable]
    [BusinessObject("04180FB9-DA6C-4824-89DD-D9E61E4FF564"), Label("功能")]
    public partial class Operation : GBusinessBase<Operation>
    {

        public Operation(OpenExpressApp.Command.CommandBase cmd)
        {
            this.Id = new Guid(cmd.Id);
            this.Command = cmd;
        }

        public OpenExpressApp.Command.CommandBase Command { get; set; }

        public Guid Id { get; private set; }

        [EntityProperty, Label("名称")]
        public string Name
        {
            get
            {
                return Command.Label;
            }
        }

        public override string ToString()
        {
            return Name;
        }

        public override bool Equals(object obj)
        {
            return this.Id == (obj as Operation).Id;
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}